﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PA3PC113.Untity;

namespace PA3PC113
{
    public partial class FrmBOSSResult : Form
    {
       
        public FrmBOSSResult()
        {
            InitializeComponent();
        }
        //计时器
        private System.Timers.Timer ClockScanDevice;
        basPA3PC113 bas113 = new basPA3PC113();
        Mes mes = new Mes();
        public void databind()
        {
            textBox1.Text += "测试开始:" + DateTime.Now.ToString() + System.Environment.NewLine;
            DataTable ds = mes.SelectMes();
            MesRst mesresult = new MesRst();
            if (ds.Rows.Count > 0)
            {
                textBox1.Text += "查询mes数据信息：" + ds.Rows.Count + System.Environment.NewLine;
                for (int i = 0; i < ds.Rows.Count; i++)
                {
                    mesresult.CurentYear = ds.Rows[i]["CurrentYear"].ToString();
                    mesresult.CurentMonth = ds.Rows[i]["CurrentMonth"].ToString();
                    mesresult.CurentDay = ds.Rows[i]["CurrentDay"].ToString();
                    mesresult.CurentHour = ds.Rows[i]["CurrentHour"].ToString();
                    mesresult.CurentMinute = ds.Rows[i]["CurrentMinute"].ToString();
                    mesresult.CurentSecond = ds.Rows[i]["CurrentSecond"].ToString();
                    mesresult.FactoryCode = ds.Rows[i]["FactoryCode"].ToString();
                    mesresult.DepartmentCode = ds.Rows[i]["DepartmentCode"].ToString();
                    mesresult.MachineNo = ds.Rows[i]["MachineNo"].ToString();
                    mesresult.OperatorCode = ds.Rows[i]["OperatorCode"].ToString();
                    //mesresult.GroupCode = ds.Rows[i]["CurrentMonth"].ToString();
                    //mesresult.ReserveArea = ds.Rows[i]["CurrentMonth"].ToString();
                    //mesresult.LotNumber = ds.Rows[i]["CurrentMonth"].ToString();
                    //mesresult.TcdSubNo = ds.Rows[i]["CurrentMonth"].ToString();
                    //mesresult.FutureUse = ds.Rows[i]["CurrentMonth"].ToString();
                    mesresult.Right_BarCode = ds.Rows[i]["Right_BarCode"].ToString();
                    //mesresult.Right_BarCodeDummy = ds.Rows[i]["Right_ProdCode"].ToString();
                    mesresult.Right_ProdCode = ds.Rows[i]["Right_ProdCode"].ToString();
                   // mesresult.Right_ProdCodeDummy = ds.Rows[i]["CurrentMonth"].ToString();
                    mesresult.Left_BarCode = ds.Rows[i]["Left_BarCode"].ToString();
                    //mesresult.Left_BarCodeDummy = ds.Rows[i]["CurrentMonth"].ToString();
                    mesresult.Left_ProdCode = ds.Rows[i]["Left_ProdCode"].ToString();
                    //mesresult.Left_ProdCodeDummy = ds.Rows[i]["CurrentMonth"].ToString();
                    mesresult.T_Spare1 = ds.Rows[i]["T_Spare1"].ToString();
                    mesresult.T_Spare2 = ds.Rows[i]["T_Spare2"].ToString();
                    mesresult.T_Spare3 = ds.Rows[i]["T_Spare3"].ToString();
                    mesresult.T_Spare4 = ds.Rows[i]["T_Spare4"].ToString();
                    mesresult.Right_CardNo = ds.Rows[i]["Right_CardNo"].ToString();
                    mesresult.Right_ProductionCode = ds.Rows[i]["Right_ProductionCode"].ToString();
                    mesresult.Right_Dummy = ds.Rows[i]["Right_Dummy"].ToString();
                    mesresult.Right_Year = ds.Rows[i]["Right_Year"].ToString();
                    mesresult.Right_Month = ds.Rows[i]["Right_Month"].ToString();
                    mesresult.Right_Day = ds.Rows[i]["Right_Day"].ToString();
                    mesresult.Right_Hour = ds.Rows[i]["Right_Hour"].ToString();
                    mesresult.Right_Minute = ds.Rows[i]["Right_Minute"].ToString();
                    mesresult.Right_Second = ds.Rows[i]["Right_Second"].ToString();
                    mesresult.Right_Result = ds.Rows[i]["Right_Result"].ToString();
                    mesresult.Right_AbnResult = ds.Rows[i]["Right_AbnResult"].ToString();
                    mesresult.Right_ExtResult = ds.Rows[i]["Right_ExtResult"].ToString();
                    mesresult.Right_FutureUse1 = ds.Rows[i]["Right_FutureUse1"].ToString();
                    mesresult.Right_FutureUse2 = ds.Rows[i]["Right_FutureUse2"].ToString();
                    mesresult.Right_FutureUse3 = ds.Rows[i]["Right_FutureUse3"].ToString();
                    mesresult.Right_FutureUse4 = ds.Rows[i]["Right_FutureUse4"].ToString();
                    mesresult.Left_CardNo = ds.Rows[i]["Left_CardNo"].ToString();
                    mesresult.Left_ProductionCode = ds.Rows[i]["Left_ProductionCode"].ToString();
                    mesresult.Left_Dummy = ds.Rows[i]["Left_Dummy"].ToString();
                    mesresult.Left_Year = ds.Rows[i]["Left_Year"].ToString();
                    mesresult.Left_Month = ds.Rows[i]["Left_Month"].ToString();
                    mesresult.Left_Day = ds.Rows[i]["Left_Day"].ToString();
                    mesresult.Left_Hour = ds.Rows[i]["Left_Hour"].ToString();
                    mesresult.Left_Minute = ds.Rows[i]["Left_Minute"].ToString();
                    mesresult.Left_Second = ds.Rows[i]["Left_Second"].ToString();
                    mesresult.Left_Result = ds.Rows[i]["Left_Result"].ToString();
                    mesresult.Left_AbnResult = ds.Rows[i]["Left_AbnResult"].ToString();
                    mesresult.Left_ExtResult = ds.Rows[i]["Left_ExtResult"].ToString();
                    mesresult.Left_FutureUse1 = ds.Rows[i]["Left_FutureUse1"].ToString();
                    mesresult.Left_FutureUse2 = ds.Rows[i]["Left_FutureUse2"].ToString();
                    mesresult.Left_FutureUse3 = ds.Rows[i]["Left_FutureUse3"].ToString();
                    mesresult.Left_FutureUse4 = ds.Rows[i]["Left_FutureUse4"].ToString();
                    mesresult.Nonum = ds.Rows[i]["Nonumber"].ToString();
                    bas113.ReceiveResultMain(mesresult);
                    textBox1.Text += "插入APS信息：" + (i + 1) + System.Environment.NewLine;
                }
            }
        }

        private void FrmBOSSResult_Load(object sender, EventArgs e)
        {
            textBox1.Text += "测试准备:" + DateTime.Now.ToString() + System.Environment.NewLine;
            Control.CheckForIllegalCrossThreadCalls = false;
            this.ClockScanDevice = new System.Timers.Timer(60000) { AutoReset = false };
            this.ClockScanDevice.Elapsed +=
                (o, args) =>
                {
                    this.ClockScanDevice.Stop();
                    
                    databind();
                    this.ClockScanDevice.Start();
                };
            this.ClockScanDevice.Start();
        }
       
    }
}
